
// JavaScript Document
//echart01*****************************************************************************************************************//
function initEchart01(val, tag)
{
	var bgColor = '';
	var showVal = 0;
	if(val<60)
	{
		bgColor = '#41CB89';
	}
	else if (val<75)
	{
		bgColor = '#FFCE49';

	}
	else if (val<85)
	{
		bgColor = '#F88B42';
	}
	else
	{
		bgColor = '#FF8298';
	}

	showVal = val * 0.75;
	valLeft = (100-val)*0.75;

	$(".echartsplit .notes").css("background",bgColor);

	var myChart = echarts.init(document.getElementById('echart01'));
	option = {
		//tooltip: {
		//	trigger: 'item',
		//	formatter: '{a} <br/>{b}: {c} ({d}%)'
		//},
		animation: false,
		grid: {
			x: 0,
			y: 20,
			x2: 30,
			y2: 100
		},
		title: {
			show:true,
			text:val,
			left: 'center',
			top: '30%',
			textStyle:{color:bgColor,fontSize:'86',fontFamily:'arial',fontWeight:'100'}
		},
		series: [
			{
				name: '',
				type: 'pie',
				radius: ['80%', '87%'],

				avoidLabelOverlap: false,
				label: {
					normal: {
						show: false,
						position: 'center'
					},
					emphasis: {
						show: false,
						textStyle: {
							fontSize: '12',
						}
					}
				},
				labelLine: {
					normal: {
						show: false
					}
				},
				data: [
					{value: 25, name: '', itemStyle: {color:'rgba(255,255,255,0)'}},
					{value: showVal, name: tag, itemStyle: {color:bgColor}},
					{value: valLeft, name: '', itemStyle: {color:'rgba(255,255,255,0)'}},
				]
			}
		]
	};
	myChart.setOption(option);
}

//echart02*****************************************************************************************************************//
function initEchart02(dataValue)
{
	var myChart = echarts.init(document.getElementById('echart02'));
	myChart.setOption(
		option = {
		animation: false,
		color: ["#00d7e0"],
		tooltip: {},
		grid: {
			x: 0,
			y: 20,
			x2: 30,
			y2: 100
		},
		radar: {
			name: {
				textStyle: {
					color: '#0A2463',
					fontSize:12,
					borderRadius: 4,
					padding: [3, 0]
			   }
			},
			indicator: [
			   { name: '心肺适能', max: 5},
			   { name: '身体成分', max: 5},
			   { name: '神经动作适能', max: 5},
			   { name: '柔韧适能', max: 5},
			   { name: '肌肉适能', max: 5}
			],
			center: ['60%','60%'],
		},
		series: [{
			type: 'radar',
			data : [
				{
					value : dataValue,
					lineStyle: {
						normal: {
							color: "#266fff",
							width: 5
						}
					},
					name:'得分'
				}
			]
			}]
	});
}

//echart03*****************************************************************************************************************//
function initEchart03(val1, val1Start, val1Lower, val1Upper, val1End, val2, val2Start, val2Lower, val2Upper, val2End, val3, val3Start, val3Lower, val3Upper, val3End){
	var showval1 = val1;
	var showval2 = val2 * val1End / val2End;
	var showval3 = val3 * val1End / val3End;
	var myChart = echarts.init(document.getElementById('echart03'));
	var myColor = ['#71BAFE', '#41CB89','#E7464C'];

	option = {
		animation: false,
		grid: {
				x: 50,
				y: 0,
				x2: 50,
				y2: 10
			},
		tooltip: {
			show:false,
		},
		xAxis: {
			show: false,
			type: 'value'
		},
		yAxis: [{
			type: 'category',
			inverse: true,
			axisLabel: {
				show: true,
				textStyle: {
					color: 'rgba(0,0,0,0.5)',
				},
			},
			splitLine: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLine: {
				show: false
			},
			data: ['体重   ', '骨骼肌', '体脂肪']
		},
		{
			type: 'category',
			inverse: true,
			axisTick: 'none',
			axisLine: 'none',
			show: true,
			axisLabel: {
				textStyle: {
					color: '#434343',
					fontSize: '12'
				},
			},
			data: [val1End, val2End, val3End]
		}],
		series: [{
            name: '数据',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    barBorderRadius: 30,
					color: function(data) {
						//修正数值
						if (data.dataIndex == 0)
						{
							data.value = data.value;
						}
						else if (data.dataIndex == 1)
						{
							data.value = data.value * val2End / val1End;
						}
						else
						{
							data.value = data.value * val3End / val1End;
						}
						if(data.dataIndex==0)
						{
							if (data.value < val1Lower)
							{
								return myColor[0];
							}
							else if (data.value < val1Upper)
							{
								return myColor[1];
							}
							else
							{
								return myColor[2];
							}
						}
						else if(data.dataIndex==1)
						{
							if (data.value < val2Lower)
							{
								return myColor[0];
							}
							else if (data.value < val2Upper)
							{
								return myColor[1];
							}
							else
							{
								return myColor[2];
							}
						}
						else
						{
							if (data.value < val3Lower)
							{
								return myColor[0];
							}
							else if (data.value < val3Upper)
							{
								return myColor[1];
							}
							else
							{
								return myColor[2];
							}
						}
					}
                },
            },
			label: {
					normal: {
						show: true,
						formatter: function(data,index)
						{
							if(data.dataIndex==0)
							{
								return data.value;
							}
							else if(data.dataIndex==1)
							{
								return data.value * val2End / val1End;
							}
							else
							{
								return data.value * val3End / val1End;
							}
						},
						fontSize: 16,
						color: '#fff',
						fontWeight: 'bold',
						position: 'insideRight'
					}
				},
            barWidth: 20,
			data: [showval1, showval2, showval3]
        },
        {
            type: 'bar',
            barWidth: 20,
            barGap: '-100%',
			data: [val1End, val1End, val1End],
            itemStyle: {
                normal: {
                    color: 'rgba(0,0,0,0.1)',
                    barBorderRadius: 30,
                }
				}
        }]
	};
	myChart.setOption(option);
}

//echart04*****************************************************************************************************************//
function initEchart04(age,val1,val2,val3,val4,val5){
	var myChart = echarts.init(document.getElementById('echart04'));
	var myColor = ['#E7464C','#41CB89'];

	option = {
		animation: false,
		grid: {
				x: 70,
				y: 10,
				x2: 50,
				y2: 30
			},
		tooltip: {
			show:false,
		},
		xAxis: {
			show: true,
			min:0,
			max:80,
			splitNumber:10,
			type: 'value',
			axisLine:{
				lineStyle:{
					color:'#485465',
				}
			}
		},
		yAxis: [{
			type: 'category',
			inverse: true,
			axisLabel: {
				show: true,
				textStyle: {
					color: 'rgba(0,0,0,0.5)',
				},
			},
			splitLine: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLine: {
				show: false
			},
			data: ['有氧年龄', '力量年龄', '柔韧年龄','平衡年龄','反应年龄']
		}],
		series: [{
            name: '数据',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    barBorderRadius: 30,
					color: function(data) {
						if(data.dataIndex==0)
						{
							if (data.value > age)
							{
								return myColor[0];
							}
							else
							{
								return myColor[1];
							}
						}
						else if(data.dataIndex==1)
						{
							if (data.value > age)
							{
								return myColor[0];
							}
							else
							{
								return myColor[1];
							}
						}
						else if(data.dataIndex==2)
						{
							if (data.value > age)
							{
								return myColor[0];
							}
							else
							{
								return myColor[1];
							}
						}
						else if(data.dataIndex==3)
						{
							if (data.value > age)
							{
								return myColor[0];
							}
							else
							{
								return myColor[1];
							}
						}
						else
						{
							if (data.value > age)
							{
								return myColor[0];
							}
							else
							{
								return myColor[1];
							}
						}
					}
                },
            },
			label: {
					normal: {
						show: true,
						fontSize: 16,
						color: '#fff',
						fontWeight: 'bold',
						position: 'insideRight'
					}
				},
            barWidth: 20,
			data: [val1, val2, val3, val4, val5]
        }]
	};
	myChart.setOption(option);
}
//获取不同级别对应的颜色
function getColor(level)
{
	switch(level)
	{
		case "bad":
			return "#E7464C";
		case "poor":
			return "#FF8694";
		case "pass":
			return "#FF9E76";
		case "good":
			return "#41CB89";
		case "excellent":
			return "#1890FF";
	}
}

//获取心肺适能
function getFitnessCardiopulmonary()
{
	var maxTakeOxygenMTOScore = $("#maxTakeOxygenMTOScore").val();
	var milepostwidth = $("#cardiopulmonary .milepost").width();
	switch (maxTakeOxygenMTOScore)
	{
		case "1":
			$("#cardiopulmonary .mileflagstatus span").css("color", "#E7464C");
			$("#cardiopulmonary .mileflagicon").css("fill","#E7464C");
			$("#cardiopulmonary .mileflag").css("left",10/100 * milepostwidth -12);
			break;
		case "2":
			$("#cardiopulmonary .mileflagstatus span").css("color", "#FF8694");
			$("#cardiopulmonary .mileflagicon").css("fill","#FF8694");
			$("#cardiopulmonary .mileflag").css("left",30/100 * milepostwidth -12);
			break;
		case "3":
			$("#cardiopulmonary .mileflagstatus span").css("color", "#FF9E76");
			$("#cardiopulmonary .mileflagicon").css("fill","#FF9E76");
			$("#cardiopulmonary .mileflag").css("left",50/100 * milepostwidth -12);
			break;
		case "4":
			$("#cardiopulmonary .mileflagstatus span").css("color", "#41CB89");
			$("#cardiopulmonary .mileflagicon").css("fill","#41CB89");
			$("#cardiopulmonary .mileflag").css("left",70/100 * milepostwidth -12);
			break;
		case "5":
			$("#cardiopulmonary .mileflagstatus span").css("color", "#1890FF");
			$("#cardiopulmonary .mileflagicon").css("fill","#1890FF");
			$("#cardiopulmonary .mileflag").css("left",90/100 * milepostwidth -12);
			break;
	}
}

//获取肌肉适能,20-39岁男性按照俯卧撑，20-39岁女性按照仰卧起坐，40岁以上按照握力
function getFitnessMuscle(age)
{
	var result = 0;
	if(age<40)
	{
		$("#muscle .mileflag").css("top",70);
		$("#muscle .milepost").css("top", 120);
		result = $("#pushUpOrSitUpPOrSScore").val();
	}
	else
	{
		$("#muscle").css("height", 130);
		result = $("#gripGScore").val();
	}

	getFitnessGripOrPushUpOrSitUp(result);
}
//获取握力适能
function getFitnessGripOrPushUpOrSitUp(fitnessstatus)
{
	var milepostwidth = $("#muscle .milepost").width();

	switch(fitnessstatus)
	{
		case "1":
			$("#muscle .mileflagstatus span").css("color", "#E7464C");
			$("#muscle .mileflagicon").css("fill","#E7464C");
			$("#muscle .mileflag").css("left",10/100 * milepostwidth -12);
			break;
		case "2":
			$("#muscle .mileflagstatus span").css("color", "#FF8694");
			$("#muscle .mileflagicon").css("fill","#FF8694");
			$("#muscle .mileflag").css("left",30/100 * milepostwidth -12);
			break;
		case "3":
			$("#muscle .mileflagstatus span").css("color", "#FF9E76");
			$("#muscle .mileflagicon").css("fill","#FF9E76");
			$("#muscle .mileflag").css("left",50/100 * milepostwidth -12);
			break;
		case "4":
			$("#muscle .mileflagstatus span").css("color", "#41CB89");
			$("#muscle .mileflagicon").css("fill","#41CB89");
			$("#muscle .mileflag").css("left",70/100 * milepostwidth -12);
			break;
		case "5":
			$("#muscle .mileflagstatus span").css("color", "#1890FF");
			$("#muscle .mileflagicon").css("fill","#1890FF");
			$("#muscle .mileflag").css("left",90/100 * milepostwidth -12);
			break;
	}
}

//获取柔韧适能
function getFitnessFlexibility(fitnessstatus)
{
	var milepostwidth = $("#flexibility .milepost").width();

	switch(fitnessstatus)
	{
		case "1":
			$("#flexibility .mileflagstatus span").css("color","#E7464C");
			$("#flexibility .mileflagicon").css("fill","#E7464C");
			$("#flexibility .mileflag").css("left",10/100 * milepostwidth -12);
			break;
		case "2":
			$("#flexibility .mileflagstatus span").css("color", "##FF8694");
			$("#flexibility .mileflagicon").css("fill","#FF8694");
			$("#flexibility .mileflag").css("left",30/100 * milepostwidth -12);
			break;
		case "3":
			$("#flexibility .mileflagstatus span").css("color", "#FF9E76");
			$("#flexibility .mileflagicon").css("fill","#FF9E76");
			$("#flexibility .mileflag").css("left",50/100 * milepostwidth -12);
			break;
		case "4":
			$("#flexibility .mileflagstatus span").css("color", "#41CB89");
			$("#flexibility .mileflagicon").css("fill","#41CB89");
			$("#flexibility .mileflag").css("left",70/100 * milepostwidth -12);
			break;
		case "5":
			$("#flexibility .mileflagstatus span").css("color", "#1890FF");
			$("#flexibility .mileflagicon").css("fill","#1890FF");
			$("#flexibility .mileflag").css("left",90/100 * milepostwidth -12);
			break;
	}

}
//获取平衡适能
function getFitnessBalanced(fitnessstatus)
{
	var milepostwidth = $("#balanced .milepost").width();

	switch(fitnessstatus)
	{
		case "1":
			$("#balanced .mileflagstatus span").css("color", "#E7464C");
			$("#balanced .mileflagicon").css("fill","#E7464C");
			$("#balanced .mileflag").css("left",10/100 * milepostwidth -12);
			break;
		case "2":
			$("#balanced .mileflagstatus span").css("color", "#FF8694");
			$("#balanced .mileflagicon").css("fill","#FF8694");
			$("#balanced .mileflag").css("left",30/100 * milepostwidth -12);
			break;
		case "3":
			$("#balanced .mileflagstatus span").css("color", "#FF9E76");
			$("#balanced .mileflagicon").css("fill","#FF9E76");
			$("#balanced .mileflag").css("left",50/100 * milepostwidth -12);
			break;
		case "4":
			$("#balanced .mileflagstatus span").css("color", "#41CB89");
			$("#balanced .mileflagicon").css("fill","#41CB89");
			$("#balanced .mileflag").css("left",70/100 * milepostwidth -12);
			break;
		case "5":
			$("#balanced .mileflagstatus span").css("color", "#1890FF");
			$("#balanced .mileflagicon").css("fill","#1890FF");
			$("#balanced .mileflag").css("left",90/100 * milepostwidth -12);
			break;
	}
}
//获取反应适能
function getFitnessReaction(fitnessstatus)
{
	var milepostwidth = $("#reaction .milepost").width();

	switch(fitnessstatus)
	{
		case "1":
			$("#reaction .mileflagstatus span").css("color", "#E7464C");
			$("#reaction .mileflagicon").css("fill","#E7464C");
			$("#reaction .mileflag").css("left",10/100 * milepostwidth -12);
			break;
		case "2":
			$("#reaction .mileflagstatus span").css("color", "#FF8694");
			$("#reaction .mileflagicon").css("fill","#FF8694");
			$("#reaction .mileflag").css("left",30/100 * milepostwidth -12);
			break;
		case "3":
			$("#reaction .mileflagstatus span").css("color", "#FF9E76");
			$("#reaction .mileflagicon").css("fill","#FF9E76");
			$("#reaction .mileflag").css("left",50/100 * milepostwidth -12);
			break;
		case "4":
			$("#reaction .mileflagstatus span").css("color", "#41CB89");
			$("#reaction .mileflagicon").css("fill","#41CB89");
			$("#reaction .mileflag").css("left",70/100 * milepostwidth -12);
			break;
		case "5":
			$("#reaction .mileflagstatus span").css("color", "#1890FF");
			$("#reaction .mileflagicon").css("fill","#1890FF");
			$("#reaction .mileflag").css("left",90/100 * milepostwidth -12);
			break;
	}
}

function getQueryString(name) {
			var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
			var r = window.location.search.substr(1).match(reg);
			if (r != null) {
			return decodeURI(r[2]);
			// return r[2];
			}
			return null;
			}

$(window).load(function () {
	// var age = $("#customerAge").val(); //年龄
	// var gender = $("#customerGender").val(); //性别
  var age = getQueryString('customerAge'); //年龄
	var gender = getQueryString('customerGender'); //性别

	// var TestScoreValue = $("#TestScoreValue").val();
	// var TestScoreValueEvaluate = $("#echart01Notes").html();
  var TestScoreValue = getQueryString('TestScoreValue');;
  var TestScoreValueEvaluate = getQueryString('echart01Notes');;
	initEchart01(TestScoreValue, TestScoreValueEvaluate);

	// var radarCardiopulmonaryScore = $("#radarCardiopulmonaryScore").val();
	// var radarBodyCompositionScore = $("#radarBodyCompositionScore").val();
	// var radarNeuromotorScore = $("#radarNeuromotorScore").val();
	// var radarFlexibilityScore = $("#radarFlexibilityScore").val();
	// var radarMuscleScore = $("#radarMuscleScore").val();
  var radarCardiopulmonaryScore = getQueryString('radarCardiopulmonaryScore');
  var radarBodyCompositionScore = getQueryString('radarBodyCompositionScore');
  var radarNeuromotorScore = getQueryString('radarNeuromotorScore');
  var radarFlexibilityScore = getQueryString('radarFlexibilityScore');
  var radarMuscleScore =getQueryString('radarMuscleScore');
	initEchart02([radarCardiopulmonaryScore, radarBodyCompositionScore, radarNeuromotorScore, radarFlexibilityScore, radarMuscleScore]);

	// var weightAnalysisWeight = $("#weightAnalysisWeight").val();
	// var weightAnalysisWeightStandardStart = $("#weightAnalysisWeightStandardStart").val();
	// var weightAnalysisWeightStandardLower = $("#weightAnalysisWeightStandardLower").val();
	// var weightAnalysisWeightStandardUpper = $("#weightAnalysisWeightStandardUpper").val();
	// var weightAnalysisWeightStandardEnd = $("#weightAnalysisWeightStandardEnd").val();
  var weightAnalysisWeight = getQueryString('weightAnalysisWeight');
  var weightAnalysisWeightStandardStart = getQueryString('weightAnalysisWeightStandardStart');
  var weightAnalysisWeightStandardLower = getQueryString('weightAnalysisWeightStandardLower');
  var weightAnalysisWeightStandardUpper = getQueryString('weightAnalysisWeightStandardUpper');
  var weightAnalysisWeightStandardEnd =getQueryString('weightAnalysisWeightStandardEnd');
  

	// var skeletalMuscleAnalysisSkeletalMuscle = $("#skeletalMuscleAnalysisSkeletalMuscle").val();
	// var skeletalMuscleAnalysisSkeletalMuscleStandardStart = $("#skeletalMuscleAnalysisSkeletalMuscleStandardStart").val();
	// var skeletalMuscleAnalysisSkeletalMuscleStandardLower = $("#skeletalMuscleAnalysisSkeletalMuscleStandardLower").val();
	// var skeletalMuscleAnalysisSkeletalMuscleStandardUpper = $("#skeletalMuscleAnalysisSkeletalMuscleStandardUpper").val();
	// var skeletalMuscleAnalysisSkeletalMuscleStandardEnd = $("#skeletalMuscleAnalysisSkeletalMuscleStandardEnd").val();
  var skeletalMuscleAnalysisSkeletalMuscle = getQueryString('skeletalMuscleAnalysisSkeletalMuscle');
  var skeletalMuscleAnalysisSkeletalMuscleStandardStart = getQueryString('skeletalMuscleAnalysisSkeletalMuscleStandardStart');
  var skeletalMuscleAnalysisSkeletalMuscleStandardLower = getQueryString('skeletalMuscleAnalysisSkeletalMuscleStandardLower');
  var skeletalMuscleAnalysisSkeletalMuscleStandardUpper = getQueryString('skeletalMuscleAnalysisSkeletalMuscleStandardUpper');
  var skeletalMuscleAnalysisSkeletalMuscleStandardEnd = getQueryString('skeletalMuscleAnalysisSkeletalMuscleStandardEnd');

	// var bodyFatAnalysisBodyFat = $("#bodyFatAnalysisBodyFat").val();
	// var bodyFatAnalysisBodyFatStandardStart = $("#bodyFatAnalysisBodyFatStandardStart").val();
	// var bodyFatAnalysisBodyFatStandardLower = $("#bodyFatAnalysisBodyFatStandardLower").val();
	// var bodyFatAnalysisBodyFatStandardUpper = $("#bodyFatAnalysisBodyFatStandardUpper").val();
	// var bodyFatAnalysisBodyFatStandardEnd = $("#bodyFatAnalysisBodyFatStandardEnd").val();
  var bodyFatAnalysisBodyFat = getQueryString('bodyFatAnalysisBodyFat');
  var bodyFatAnalysisBodyFatStandardStart = getQueryString('bodyFatAnalysisBodyFatStandardStart');
  var bodyFatAnalysisBodyFatStandardLower = getQueryString('bodyFatAnalysisBodyFatStandardLower');
  var bodyFatAnalysisBodyFatStandardUpper = getQueryString('bodyFatAnalysisBodyFatStandardUpper');
  var bodyFatAnalysisBodyFatStandardEnd = getQueryString('bodyFatAnalysisBodyFatStandardEnd');
	initEchart03(weightAnalysisWeight, weightAnalysisWeightStandardStart, weightAnalysisWeightStandardLower, weightAnalysisWeightStandardUpper, weightAnalysisWeightStandardEnd, skeletalMuscleAnalysisSkeletalMuscle, skeletalMuscleAnalysisSkeletalMuscleStandardStart, skeletalMuscleAnalysisSkeletalMuscleStandardLower, skeletalMuscleAnalysisSkeletalMuscleStandardUpper, skeletalMuscleAnalysisSkeletalMuscleStandardEnd, bodyFatAnalysisBodyFat, bodyFatAnalysisBodyFatStandardStart, bodyFatAnalysisBodyFatStandardLower, bodyFatAnalysisBodyFatStandardUpper, bodyFatAnalysisBodyFatStandardEnd);

	// var bodyAgemaxTakeOxygenAge = $("#bodyAgemaxTakeOxygenAge").val();
	// var bodyAgegripAge = $("#bodyAgegripAge").val();
	// var bodyAgesitForwardAge = $("#bodyAgesitForwardAge").val();
	// var bodyAgecloseEyeOneLegStandAge = $("#bodyAgecloseEyeOneLegStandAge").val();
	// var bodyAgeselectReactionTimeAge = $("#bodyAgeselectReactionTimeAge").val();
  var bodyAgemaxTakeOxygenAge = getQueryString('bodyAgemaxTakeOxygenAge');
  var bodyAgegripAge = $getQueryString('bodyAgegripAge');
  var bodyAgesitForwardAge = getQueryString('bodyAgesitForwardAge');
  var bodyAgecloseEyeOneLegStandAge = getQueryString('bodyAgecloseEyeOneLegStandAge');
  var bodyAgeselectReactionTimeAge = getQueryString('bodyAgeselectReactionTimeAge');
	initEchart04(age,bodyAgemaxTakeOxygenAge, bodyAgegripAge, bodyAgesitForwardAge, bodyAgecloseEyeOneLegStandAge, bodyAgeselectReactionTimeAge);

	//获取心肺适能
	getFitnessCardiopulmonary();

	//获取肌肉适能
	getFitnessMuscle(age);

	//获取柔韧适能
	// getFitnessFlexibility($("#sitForwardSitForwardValueScore").val());
	getFitnessFlexibility(getQueryString('sitForwardSitForwardValueScore'));

	//获取平衡适能
	// getFitnessBalanced($("#StandWithEyesClosedValueScore").val());
	getFitnessBalanced(getQueryString('StandWithEyesClosedValueScore'));

	//获取反应适能
	// getFitnessReaction($("#SelectReactionTimeValueScore").val());
	getFitnessReaction(getQueryString('SelectReactionTimeValueScore'));
});
